package com.breadwallet.presenter.entities;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class NoticeItem {


    /**
     * new_id : 34
     * title : c0ban1111
     * is_img : 1
     * read_num : 1
     * create_time : 2018-11-22 14:06:38
     * content :
     * is_read : 2
     */

    public String new_id;
    public String title;
    public String is_img;
    public String read_num;
    public String create_time;
    public String content;
    public int is_read;

    public static List<NoticeItem> getFromJSONArray(JSONArray array){
        List<NoticeItem> noticeItems = new ArrayList<>();
        if(array==null||array.length()==0){
            return noticeItems;
        }
        for (int i = 0; i < array.length(); i++) {
            try {
                JSONObject o = (JSONObject) array.get(i);
                NoticeItem item = new NoticeItem();
                item.new_id = o.optString("new_id");
                item.title = o.optString("title");
                item.is_img = o.optString("is_img");
                item.read_num = o.optString("read_num");
                item.create_time = o.optString("create_time");
                item.content = o.optString("content");
                item.is_read = o.optInt("is_read");
                noticeItems.add(item);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return noticeItems;

    }

}